﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TruckWatch.Cloud.DAL;
using System.Web.Mvc;
using TruckWatch.Cloud.BusinessLogic;
using TruckWatch.Cloud.Models.EF;

namespace Mvc30WebRole1.Util
{
    public static class HtmlUtil
    {

        public static IEnumerable<SelectListItem> RenderLocationDropdown()
        {
            List<Location> loctations = LocationBL.GetAllLocations();

            foreach (var item in loctations)
            {
                yield return new SelectListItem() { Text = item.LocationName, Value = item.Id.ToString() };
            }
        }

        public static string RenderDBInfo()
        {
            try
            {
                string db = DataGeneral.GetDBServerName();
                return "Connection: " + db;
            }
            catch (Exception ex)
            {
                return "unable to determine Connection " + ex.Message;
            }
        }

        public static IEnumerable<SelectListItem> RenderDrivers(string selectedUserId = null, bool includeBlank = false, bool includeBroadcast = false)
        {
            List<Driver> drivers = DriverBLEF.GetAllDrivers();

            if (includeBlank)
                yield return new SelectListItem() { Value = "0", Text = "(Select driver)" };
            foreach (Driver driver in drivers)
            {
                if (driver.Id == GeneralSettings.BroadCastDriverId && includeBroadcast == false)
                    continue;
                yield return new SelectListItem() { Value = driver.UserId, Text = string.Format("{0} ({1})", driver.Name, driver.UserId), Selected = (driver.UserId.Equals(selectedUserId, StringComparison.OrdinalIgnoreCase)) };
            }
        }
    }
}